package main

import (
	"encoding/gob"
	"fmt"
	"os"
)

// 写一个程序读取 vcard.gob 文件，解码并打印它的内容。

type Address struct {
	Type, City, Country string
}

type VCard struct {
	Name      string
	Addresses []*Address
	Remark    string
}

func main() {
	var vc VCard
	file, err := os.Open("vcard.gob")
	if err != nil {
		fmt.Fprintf(os.Stderr, "degob: open error: %s\n", err)
		os.Exit(1)
	}
	defer file.Close()

	// 创建指定文件的Decoder
	dec := gob.NewDecoder(file)
	// 解析gob内容并赋给vc变量
	err = dec.Decode(&vc)
	if err != nil {
		fmt.Fprintf(os.Stderr, "degob: decode error: %s\n", err)
		os.Exit(1)
	}
	fmt.Printf("vcard.name: %s\n", vc.Name)
	for _, addr := range vc.Addresses {

		fmt.Printf("vcard.Address: %v\n", addr)
	}
	fmt.Printf("vcard.remark: %s\n", vc.Remark)
}
